package com.example.myFirstWebmagic.airQualityForecasting;

import java.util.List;
import java.util.Map;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

public class AirqualityForecastPipeline implements Pipeline {

	private final AirqualityForecastDao repository;
	
	public AirqualityForecastPipeline(AirqualityForecastDao repository){
		this.repository=repository;
	}
	@Override
	public void process(ResultItems resultItems, Task task) {
		// TODO Auto-generated method stub
		 //遍历所有结果，保存到数据库
        for (Map.Entry<String, Object> entry : resultItems.getAll().entrySet()) {
            @SuppressWarnings("unchecked")
			List<EnAirqualityForecast> list= (List<EnAirqualityForecast>) entry.getValue();
            for(EnAirqualityForecast report:list){
            	repository.save(report);
            }
        }
	}

}
